<script setup lang="ts">
import { hc } from "@/framework/vue/util/render.ts";
import { AppstoreOutlined, SettingOutlined, UserOutlined } from "@ant-design/icons-vue";
import { computed } from "vue";
import { CmdTools } from "@/util/cmd-tools.ts";

const { name, value } = defineProps<{
  name: string;
  value?: string;
}>();

const disabled = computed(() => !name || !value);

const setEnv = (user = true) => {
  if (user) {
    CmdTools.envs.setUserEnv(name, value!);
  } else {
    CmdTools.envs.setSystemEnv(name, value!);
  }
};
</script>

<template>
  <a-dropdown :open="disabled ? false : undefined">
    <a-button :disabled="disabled" :icon="hc(SettingOutlined)">设置为</a-button>
    <template #overlay>
      <a-menu>
        <a-menu-item :icon="hc(UserOutlined)" @click="setEnv()">用户变量</a-menu-item>
        <a-menu-item :icon="hc(AppstoreOutlined)" @click="setEnv(false)">系统变量</a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
</template>

<style scoped lang="less"></style>
